<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="敏感词" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="敏感词"
          clearable
          size="small"
          @input="handleQuery"
        />
      </el-form-item>

      <el-form-item label="操作员工" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="支持搜索发表用户和被评论的用户"
          clearable
          size="small"
          @input="handleQuery"
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item label="操作时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
     



      <el-form-item>
        <el-button type="primary" icon="Search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div class="layout-content">
      <el-row class="table-header">
        <span>敏感词</span>
        <div class="right">
        <el-button 
        type="primary"  
        size="mini" @click="addSensitiveWord"
          >新增</el-button
        >
        </div>
      </el-row>

      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="
          tableData.filter(
            (data) =>
              !search || data.name.toLowerCase().includes(search.toLowerCase())
          )
        "
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="操作"
          align="left"
          width="150"
        >
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              @click="editorline(scope.row)"
              >编辑</el-button
            >
            <span class="shu">|</span>
              <el-button
              size="mini"
              type="text"
              @click="deleteline(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
   <el-table-column label="敏感词" prop="sensitiveWord">
          <template #default="scope">
            <div class="line1">
              {{ scope.row.sensitiveWord }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作员工" prop="phone" />
      
        <el-table-column label="操作时间" prop="createTime">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.current"
        v-model:limit="queryParams.size"
        @pagination="getList"
      />
    </div>
  </div>
</template>
<script setup name="UserList">
import { listModel, infoModel } from "@/api/model/list";
import { commit } from "@/api/speech/commit";
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const search = ref("");
const total = ref("0");
const loading = ref(true);
const router = useRouter();
const dateRange = ref([]);
const ids = ref([]);
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");

// 搜索栏的显隐
const showSearch = ref(true);




// 获取用户的选中
const multipleSelection = ref("");
const queryParams = reactive({
  current: 1,
  size: 10,
  keyword: undefined,
  username: undefined,
  status: undefined,
});

// 用户数据列表
const tableData = ref([]);
// 获取用户数据列表
function getList() {
  loading.value = true;
  commit(queryParams).then((response) => {
    console.log("response.data", response.data);
    total.value = response.data.total;
    tableData.value = response.data.records;
    loading.value = false;
  });
}

/** 添加敏感词按钮操作 */
function addSensitiveWord() {
     proxy.$prompt('敏感词：', "添加敏感词", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    closeOnClickModal: false,
    inputErrorMessage: "请输入敏感词",
  }).then(({ value }) => {
    resetUserPwd(row.userId, value).then(response => {
      proxy.$modal.msgSuccess("编辑成功，新敏感词是：" + value);
    });
  }).catch(() => {});
}



/** 编辑按钮操作 */
function editorline(row) {
  proxy.$prompt('敏感词：', "编辑敏感词", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    closeOnClickModal: false,
    inputErrorMessage: "请输入敏感词",
  }).then(({ value }) => {
    resetUserPwd(row.userId, value).then(response => {
      proxy.$modal.msgSuccess("编辑成功，新敏感词是：" + value);
    });
  }).catch(() => {});
};

/** 删除按钮操作 */
function deleteline(row) {
  const userIds = row.userId || ids.value;
  const sensitiveName = '111敏感词111';
  proxy.$modal.confirm('确定删除敏感词' + sensitiveName + '吗？').then(function () {
    return delUser(userIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
};




/** 搜索按钮操作 */
function handleQuery() {
  queryParams.current = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  getList();
}


getList();
</script>
<style lang="scss">


</style>
